package com.resource.project.controller.system;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.resource.project.entity.RespBean;
import com.resource.project.entity.system.Hr;
import com.resource.project.entity.system.Menu;
import com.resource.project.entity.system.Role;
import com.resource.project.os.HrVo;
import com.resource.project.service.system.service.IHrService;
import com.resource.project.service.system.service.IMenuRoleService;
import com.resource.project.service.system.service.IMenuService;
import com.resource.project.service.system.service.IRoleService;
import com.resource.util.page.PageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author resource
 * @since 2020-03-14
 */
@RestController
@RequestMapping("/project/role")
@Api(tags = "角色管理")
public class RoleController {
    @Autowired
    private IRoleService roleService;
    @Autowired
    private IMenuService menuService;
    @Autowired
    private IMenuRoleService menuRoleService;
    @ApiOperation(value = "查询所有角色")
    @GetMapping
    public List<Role> getAllPostions(){
        return roleService.roles();
    }

    @ApiOperation(value = "查询菜单")
    @GetMapping("/menus")
    public List<Menu> getAllMenus(){
        return menuService.getAllMenuWithRole();
    }

    @ApiOperation(value = "根据角色查询菜单")
    @GetMapping("/{id}")
    public List<Long> getAllMenusByRole(@PathVariable Long id){
        return menuService.getAllMenuByRole(id);
    }

    @ApiOperation(value = "根据角色id修改菜单")
    @PutMapping
    public RespBean updateMenuByRoleId(Long id, @RequestBody Long[] mids){
        if(menuRoleService.updateMenuByRoleId(id,mids)){
            return RespBean.ok("修改成功");
        }
        return RespBean.error("修改失败");
    }
    @ApiOperation(value = "新增角色")
    @PostMapping("/addRole")
    public RespBean addRole(@RequestBody  Role role){
        return roleService.addRole(role);
    }

    @ApiOperation(value = "删除角色")
    @DeleteMapping("/deleteRole")
    public RespBean deleteRole(Long id){
        return roleService.deleteRole(id);
    }
}
